package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysHotelRoom;
import com.ruoyi.system.service.ISysHotelRoomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房型Controller
 * 
 * @author dht
 * @date 2025-04-28
 */
@RestController
@RequestMapping("/system/room")
public class SysHotelRoomController extends BaseController
{
    @Autowired
    private ISysHotelRoomService sysHotelRoomService;

    /**
     * 查询房型列表
     */
    @PreAuthorize("@ss.hasPermi('system:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysHotelRoom sysHotelRoom)
    {
        startPage();
        List<SysHotelRoom> list = sysHotelRoomService.selectSysHotelRoomList(sysHotelRoom);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:room:list')")
    @GetMapping("/list/{hotelId}")
    public AjaxResult listByHotelId(@PathVariable("hotelId") Long hotelId)
    {
        return success(sysHotelRoomService.listByHotelId(hotelId));

    }

    /**
     * 导出房型列表
     */
    @PreAuthorize("@ss.hasPermi('system:room:export')")
    @Log(title = "房型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysHotelRoom sysHotelRoom)
    {
        List<SysHotelRoom> list = sysHotelRoomService.selectSysHotelRoomList(sysHotelRoom);
        ExcelUtil<SysHotelRoom> util = new ExcelUtil<SysHotelRoom>(SysHotelRoom.class);
        util.exportExcel(response, list, "房型数据");
    }

    /**
     * 获取房型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:room:query')")
    @GetMapping(value = "/{hotelRoomId}")
    public AjaxResult getInfo(@PathVariable("hotelRoomId") Long hotelRoomId)
    {
        return success(sysHotelRoomService.selectSysHotelRoomByHotelRoomId(hotelRoomId));
    }

    /**
     * 新增房型
     */
    @PreAuthorize("@ss.hasPermi('system:room:add')")
    @Log(title = "房型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysHotelRoom sysHotelRoom)
    {
        return toAjax(sysHotelRoomService.insertSysHotelRoom(sysHotelRoom));
    }

    /**
     * 修改房型
     */
    @PreAuthorize("@ss.hasPermi('system:room:edit')")
    @Log(title = "房型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysHotelRoom sysHotelRoom)
    {
        return toAjax(sysHotelRoomService.updateSysHotelRoom(sysHotelRoom));
    }

    @PreAuthorize("@ss.hasPermi('system:room:edit')")
    @Log(title = "房型", businessType = BusinessType.UPDATE)
    @PutMapping("/batch")
    public AjaxResult editBatch(@RequestBody List<SysHotelRoom> sysHotelRooms)
    {
        return toAjax(sysHotelRoomService.editBatch(sysHotelRooms));
    }

    /**
     * 删除房型
     */
    @PreAuthorize("@ss.hasPermi('system:room:remove')")
    @Log(title = "房型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hotelRoomIds}")
    public AjaxResult remove(@PathVariable Long[] hotelRoomIds)
    {
        return toAjax(sysHotelRoomService.deleteSysHotelRoomByHotelRoomIds(hotelRoomIds));
    }
}
